import asunit.framework.TestCase;

import org.molamil.acto.commands.factory.XmlCommandFactory;
import org.molamil.acto.commands.factory.DependsError;

/**
 * @author Jorge Hernandez
 */
class org.molamil.acto.commands.factory.XmlCommandFactoryTest extends TestCase {
	
	
	private var className:String = "org.molamil.acto.props.XmlCommandFactory";
	private var instance:XmlCommandFactory;

	
	public function setUp():Void {
		instance = new XmlCommandFactory();
	}

	public function tearDown():Void {
		delete instance;
	}

	public function testInstantiated():Void {
		assertTrue("CommandsParser instantiated", instance instanceof XmlCommandFactory);
	}
	
	/**
	 * @see org.molamil.acto.commands.CommandsParserTest
	 */
	public function testLoadConf() {
		
		var xml:XML;
		
		var sDependsSelf:String = '' +
			'<commands>' +
    			'<command name="login" title="Login functionality" class="foo.LoginCmd"' + 
    				'target="http://www.molamil.org/Login" role="" depends="login" />'
			'</commands>';
		
		xml = new XML(sDependsSelf);
		
		try {
			instance.loadConf(xml);
			fail("Depends self didn't throw an error");
		} catch (e:DependsError) {}
		
		var sDependsDuplicate:String = '' +
			'<commands>' +
    			'<command name="login" title="Login functionality" class="foo.LoginCmd"' + 
    				'target="http://www.molamil.org/Login" role="" depends="signup, signup" />' +
    			'<command name="signup" class="foo.SignupCmd"' + 
    				'target="http://www.molamil.org/Sginup" depends="login, login" />' +
			'</commands>';
		
		xml = new XML(sDependsDuplicate);
		
		try {
			instance.loadConf(xml);
			fail("Depends duplicate didn't throw an error");
		} catch (e:DependsError) {}
		
		var sDependsNotFound:String = '' +
			'<commands>' +
    			'<command name="login" title="Login functionality" class="foo.LoginCmd"' + 
    				'target="http://www.molamil.org/Login" role="" depends="someCommand" />' +
			'</commands>';
		
		xml = new XML(sDependsNotFound);
		
		try {
			instance.loadConf(xml);
			fail("Depends not found didn't throw an error");
		} catch (e:DependsError) {}

	}

	
}